/*
 * 
 * Created on Jul 28, 2005
 */
package remato.client.view.editor.usertypes;

import java.text.Collator;
import java.util.Arrays;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;

import remato.client.model.AbstractPropertySpesification;
import remato.client.model.PropertySpesificationComparator;

/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: UserTypesTableSorter.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 * 
 * Changelog:
 * 
 * $Log: UserTypesTableSorter.java,v $
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.1  2005-12-05 04:16:41  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005-12-03 14:38:48  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/11/16 16:43:28  petterei
 * mye testing...
 *
 * Revision 1.1  2005/08/23 06:38:13  peide3
 * *** empty log message ***
 *
 * Revision 1.1  2005/07/31 22:55:10  petterei
 * initial commit
 *
 *
 */
class UserTypesTableSorter extends ViewerSorter {

    /**
     * 
     */
    public UserTypesTableSorter() {
        super();
    }

    /**
     * @param collator
     */
    public UserTypesTableSorter(Collator collator) {
        super(collator);
    }

    /**
     * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    @Override
    public int compare(Viewer viewer, Object e1, Object e2) {
        if (e1 instanceof AbstractPropertySpesification && e2 instanceof AbstractPropertySpesification) {
            return ((AbstractPropertySpesification)e1).compareTo((AbstractPropertySpesification)e2);
        }
        return super.compare(viewer, e1, e2);
    }

    /**
     * @see org.eclipse.jface.viewers.ViewerSorter#sort(org.eclipse.jface.viewers.Viewer, java.lang.Object[])
     */
    @Override
    public void sort(Viewer viewer, Object[] elements) {
        if (elements instanceof AbstractPropertySpesification[]) {
        	AbstractPropertySpesification[] specs = (AbstractPropertySpesification[])elements;
            Arrays.sort(specs, new PropertySpesificationComparator());
        } else {
            super.sort(viewer, elements);
        }
    }
}
